﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//Author: ljj
//Function: 单体攻击
public class SingleAttack : BaseAttack
{
    private GameObject target;

    public SingleAttack(GameObject attacker, GameObject target,float damage)
    {
        this.attacker = attacker;
        this.target = target;
        this.damage = damage; 
    }

    public override void Attack()
    {
        if (target !=null)
        {
            BattleObject targetBattle = target.GetComponent<BattleObject>();
            if (buffAdderOnAttack != null)
                buffAdderOnAttack.AddBuffToObj(targetBattle.gameObject);
            targetBattle.attacked(damage); 
            if (attacker != null)
            {
                BattleObject battle = attacker.GetComponent<BattleObject>();
                if (battle != null)
                    battle.addDamageScore(damage);
            }
        }
    }

    public override Vector3 GetTargetPos()
    {
        if (target == null)
            return Vector3.zero;
        else 
            return target.transform.position;
    }
}
